package edu.bbu.license.client.android.controller.main;

import edu.bbu.license.client.android.controller.BaseController;
import edu.bbu.license.client.android.gui.main.MainView;
import edu.bbu.license.client.android.services.BaseService;

public class MainController extends BaseController {
	
	private volatile MainView mainView = null;
	private static MainController controllerInstance = null;
	
	private MainController() { }
	
	public static synchronized MainController getInstance() {
		if(controllerInstance == null) {
			controllerInstance = new MainController();
		}
		
		return controllerInstance;
	}

	public synchronized void atach(MainView mainView) {
		if(mainView != null) {			
			this.mainView = mainView;
			initializeView();
		}
	}
	
	private void initializeView() {		
		if(((BaseService) getAutentificationService()).isUserLoggedIn()) {
			mainView.openFilesView();
		} else {
			mainView.openGuestView();
		}
		
		mainView.closeView();
	}
}
